from django.core.management.base import BaseCommand
from django.contrib.auth import get_user_model
from apps.users.models import UserProfile

User = get_user_model()

class Command(BaseCommand):
    help = 'Create a default admin user'

    def handle(self, *args, **options):
        # Check if admin user already exists
        if User.objects.filter(username='admin').exists():
            self.stdout.write(self.style.WARNING('Admin user already exists'))
            return

        # Create admin user
        admin_user = User.objects.create_superuser(
            username='admin',
            email='admin@aiaoes.com',
            password='admin123456',
            real_name='系统管理员',
            role='admin'
        )

        # Create user profile
        UserProfile.objects.create(
            user=admin_user,
            bio='系统默认管理员账号'
        )

        self.stdout.write(self.style.SUCCESS('Successfully created admin user'))
        self.stdout.write(self.style.SUCCESS('Username: admin'))
        self.stdout.write(self.style.SUCCESS('Password: admin123456'))
        self.stdout.write(self.style.SUCCESS('Email: admin@aiaoes.com'))